package com.haoshuang.zhouzhoubang.ui.page.settled.facerecognition

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.FaceParamsBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData


class FaceRecognitionViewModel : BaseViewModel() {

    /**
     * 获取人脸识别参数信息
     */
    val getFaceParamsData = StatefulMutableLiveData<ResponseBean<FaceParamsBean>>()
    fun getFaceParams(certName: String?, certNo: String?, metaInfo: String?) = netRequest {
        start { getFaceParamsData.value = StateData.Loading }
        request { ApiRepo.getFaceParam(certName, certNo, metaInfo) }
        success { getFaceParamsData.value = StateData.Success(it) }
        error { code, msg ->
            getFaceParamsData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 人脸识别回调
     */
    val faceRecognitionCallbackData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun faceRecognitionCallback() = netRequest {
        start { faceRecognitionCallbackData.value = StateData.Loading }
        request { ApiRepo.faceRecognitionCallback()  }
        success { faceRecognitionCallbackData.value = StateData.Success(it) }
        error { code, msg ->
            faceRecognitionCallbackData.value = StateData.Error(code, msg)
        }
    }

}